module ecs{
    export class ComponentList{
        // IUpdatable列表的全局updateOrder排序
        private static compareUpdatableOrder: IUpdatableComparer = new IUpdatableComparer();
        private _entity: Entity;
        private _components: FastList<Component> = new FastList<Component>();
        private _updatableComponents: FastList<IUpdatable> = new FastList<IUpdatable>();

        public _componentsToAdd: Array<Component> = [];

        constructor(entity: Entity){
            this._entity = entity;
        }

        public Add(component: Component){
            this._componentsToAdd.push(component);
        }

        public Update(){
            // TODO: update component
        }

        public OnEntityTransformChanged(comp: transform.Component){
            for (let i = 0; i < this._components.Length; i++) {
                if (this._components.Buffer[i].Enabled)
                    this._components.Buffer[i].OnEntityTransformChanged(comp);
            }

            for (let i = 0; i < this._componentsToAdd.length; i++) {
                if (this._componentsToAdd[i].Enabled)
                    this._componentsToAdd[i].OnEntityTransformChanged(comp);
            }
        }

        public OnEntityEnabled(){
            for (let i = 0; i < this._components.Length; i++) {
                this._components.Buffer[i].OnEnabled();
            }
        }

        public OnEntityDisabled(){
            for (let i = 0; i < this._components.Length; i++) {
                this._components.Buffer[i].OnDisabled();
            }
        }
    }
}